package org.point.controller;


import java.security.NoSuchAlgorithmException;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.point.common.controller.BaseController;
import org.point.common.util.RSAUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * 中央控制器
 * 用于jsp页面的跳转
 */
@Controller
public class AViewIndentController extends BaseController {
	
	/**
	 * (跳转到登录页面) 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "login.do")
	public String goLogin(HttpServletRequest request, HttpServletResponse response) {
		HashMap<String, Object> map;
		try {
		  map = RSAUtils.getKeys();
		  //生成公钥和私钥    
		  RSAPublicKey publicKey = (RSAPublicKey) map.get("public");  
		  RSAPrivateKey privateKey = (RSAPrivateKey) map.get("private");  
		  //私钥保存在session中，用于解密  
		  getSession().setAttribute("privateKey", privateKey);  
		  //公钥信息保存在页面，用于加密  
		  String publicKeyExponent = publicKey.getPublicExponent().toString(16);  
		  String publicKeyModulus = publicKey.getModulus().toString(16);  
		  
		  request.setAttribute("publicKeyExponent", publicKeyExponent);  
		  request.setAttribute("publicKeyModulus", publicKeyModulus);
		  return "users/login";
		}catch (NoSuchAlgorithmException e) {
		  throw new RuntimeException("签名失败！", e);
		}
	}
	
	
	
	/**
	 * (跳转到登录页面) 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "index.do")
	public String index() {
		return "index";
	}
	
	/**
	 * 
	 */
	@RequestMapping(value = "credits_creditsType.do")
	public String credits_creditsType() {
		return "credits/creditsType";
	}
}
